package com.ruoyi.user.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.user.domain.UserLabel;
import com.ruoyi.user.service.IUserLabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 客户标签设置Controller
 *
 * @author ruoyi
 * @date 2025-04-10
 */
@RestController
@RequestMapping("/userLabel/userLabel")
public class UserLabelController extends BaseController {
    @Autowired
    private IUserLabelService userLabelService;

    /**
     * 查询客户标签设置列表
     */
    @PreAuthorize("@ss.hasPermi('userLabel:userLabel:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserLabel userLabel) {
        startPage();
        List<UserLabel> list = userLabelService.selectUserLabelList(userLabel);
        return getDataTable(list);
    }

    /**
     * 导出客户标签设置列表
     */
    @PreAuthorize("@ss.hasPermi('userLabel:userLabel:export')")
    @Log(title = "客户标签设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserLabel userLabel) {
        List<UserLabel> list = userLabelService.selectUserLabelList(userLabel);
        ExcelUtil<UserLabel> util = new ExcelUtil<UserLabel>(UserLabel.class);
        util.exportExcel(response, list, "客户标签设置数据");
    }

    /**
     * 获取客户标签设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('userLabel:userLabel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(userLabelService.selectUserLabelById(id));
    }

    /**
     * 新增客户标签设置
     */
    @PreAuthorize("@ss.hasPermi('userLabel:userLabel:add')")
    @Log(title = "客户标签设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserLabel userLabel) {
        return toAjax(userLabelService.insertUserLabel(userLabel));
    }

    /**
     * 修改客户标签设置
     */
    @PreAuthorize("@ss.hasPermi('userLabel:userLabel:edit')")
    @Log(title = "客户标签设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserLabel userLabel) {
        return toAjax(userLabelService.updateUserLabel(userLabel));
    }

    /**
     * 删除客户标签设置
     */
    @PreAuthorize("@ss.hasPermi('userLabel:userLabel:remove')")
    @Log(title = "客户标签设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(userLabelService.deleteUserLabelByIds(ids));
    }
}
